package org.dromara.learning_lhz.controller;

import org.dromara.learning_lhz.entity.AsStudentAdminEntity;
import org.dromara.learning_lhz.service.StudentAdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 学生管理员控制器类
 * 负责处理与学生管理员相关的HTTP请求，并调用相应的服务进行处理
 */
@RequestMapping("studentAdmin")
@RestController
public class StudentAdminController {

    // 注入学生管理员服务
    @Autowired
    private StudentAdminService studentAdminService;

    /**
     * 添加学生
     * 接收POST请求并保存学生信息
     *
     * @param asStudentAdminEntity 学生实体类，包含要添加的学生信息
     */
    @PostMapping("addStudentAdmin")
    public void addStudentAdmin(@RequestBody AsStudentAdminEntity asStudentAdminEntity)
    {
        studentAdminService.save(asStudentAdminEntity);
    }

    /**
     * 删除学生
     * 接收POST请求并根据学生信息进行删除操作
     *
     * @param asStudentAdminEntity 学生实体类，包含要删除的学生信息
     */
    @PostMapping("delStudentAdmin")
    public void delStudentAdmin(@RequestBody AsStudentAdminEntity asStudentAdminEntity)
    {
        studentAdminService.removeById(asStudentAdminEntity);
    }

    /**
     * 查询学生
     * 接收POST请求并根据条件查询学生信息
     *
     * @param asStudentAdminEntity 查询条件，包含要查询的学生的相关信息
     * @return 返回查询到的学生列表
     */
    @PostMapping("selStudentAdmin")
    public List<AsStudentAdminEntity> selStudentAdmin(@RequestBody AsStudentAdminEntity asStudentAdminEntity)
    {
        return studentAdminService.selStudentAdmin(asStudentAdminEntity);
    }

    /**
     * 更新学生信息
     * 接收POST请求并更新学生信息
     *
     * @param asStudentAdminEntity 学生实体类，包含更新后的学生信息
     */
    @PostMapping("updateStudentAdmin")
    public void updateStudentAdmin(@RequestBody AsStudentAdminEntity asStudentAdminEntity)
    {
        studentAdminService.updateById(asStudentAdminEntity);
    }

}
